//
//  CustomerReviewCell.m
//  AmazingShopping
//
//  Created by Tan on 4/24/13.
//  Copyright (c) 2013 Tan Hoang. All rights reserved.
//

#import "CustomerReviewCell.h"

@implementation CustomerReviewCell

@synthesize reviewType, reviewNumber, reviewTypeLabel, reviewNumberLabel, starReview, ratePoint;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setReviewType:(NSString *)rt{
    if (![reviewType isEqualToString:rt]) {
        reviewType = [rt copy];
        reviewTypeLabel.text = reviewType;
    }
}

- (void)setReviewNumber:(NSInteger)rn{
    reviewNumber = rn;
    reviewNumberLabel.text = [NSString stringWithFormat:@"(%ld)", (long) reviewNumber];
}

- (void)setRatePoint:(float)rp{
    if ((rp > 0) && (rp <= 5)){
        ratePoint = rp;
    }else{
        ratePoint = 0;
    }
    
    int temp = (int)ratePoint;

    if (ratePoint == 0) {
        for (int i = 0; i < [starReview count]; i++) {
            [[starReview objectAtIndex:i] setImage:[UIImage imageNamed:@"rate0.png"]];
        }
    }else{
        for (int i = 0; i < temp; i++) {
            [[starReview objectAtIndex:i] setImage:[UIImage imageNamed:@"rate1.png"]];
        }
        if (ratePoint - temp > 0) {
            [[starReview objectAtIndex:temp] setImage:[UIImage imageNamed:@"rate2.png"]];
        }else{
            [[starReview objectAtIndex:4] setImage:[UIImage imageNamed:@"rate0.png"]];
        }
        
        for (int i = temp + 1; i < [starReview count]; i++) {
            [[starReview objectAtIndex:i] setImage:[UIImage imageNamed:@"rate0.png"]];
        }
    }    
}

@end
